angular.module('app.controllers', [])

    .controller('dictListPageCtrl', ['$scope', '$stateParams', 'dictService', // The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
        function ($scope, $stateParams, dictService) {
            // var me = this;
            $scope.dicts = [];

            $scope.dicts = [
                {
                    id: 1,
                    title: 'hello',
                },
                {
                    id: 1,
                    title: 'hello',
                },
                {
                    id: 1,
                    title: 'hello',
                },
                {
                    id: 1,
                    title: 'hello',
                },
            ]
            var freshList = function () {
                dictService.getDictList().then(function (response) {
                    $scope.dicts = response.data;
                })
            }

            // this.$onInit = function () {
            // freshList();
            // }
        }])

    .controller('wordListPageCtrl', ['$scope', '$stateParams', 'dictService',// The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
        function ($scope, $stateParams, dictService) {
            $scope.words = [];
            $scope.wordsList = [
                {
                    id: 1,
                    title: 'hello',
                    sentence: 'hello world',
                    meaning: '你好'
                },
                {
                    id: 1,
                    title: 'hello',
                    sentence: 'hello world',
                    meaning: '你好'
                },
                {
                    id: 1,
                    title: 'hello',
                    sentence: 'hello world',
                    meaning: '你好'
                },
                {
                    id: 1,
                    title: 'hello',
                    sentence: 'hello world',
                    meaning: '你好'
                },
                {
                    id: 1,
                    title: 'hello',
                    sentence: 'hello world',
                    meaning: '你好'
                },
            ];

            var freshWord = function () {
                dictService.getWordList($stateParams.id).then(function (response) {
                    $scope.wordsList = response.data;
                })
            };

            // freshWord();
        }])

    .controller('wordDetailPageCtrl', ['$scope', '$stateParams', 'dictService',// The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
// You can include any angular dependencies as parameters for this function
// TIP: Access Route Parameters for your page via $stateParams.parameterName
        function ($scope, $stateParams, dictService) {
            var startTime;
            $scope.words = [];
            $scope.currentIndex = $stateParams.index;
            var oldIndex = $scope.currentIndex;

            // $scope.options = {
            //     loop: false,
            //     effect: 'slide',
            //     speed: 500,
            // };

            $scope.words = [
                {
                    id: 1,
                    title: 'hello',
                    sentence: 'hello world',
                    meaning: '你好'
                },
                {
                    id: 1,
                    title: 'hello',
                    sentence: 'hello world',
                    meaning: '你好'
                },
                {
                    id: 1,
                    title: 'hello',
                    sentence: 'hello world',
                    meaning: '你好'
                },
                {
                    id: 1,
                    title: 'hello',
                    sentence: 'hello world',
                    meaning: '你好'
                },
                {
                    id: 1,
                    title: 'hello',
                    sentence: 'hello world',
                    meaning: '你好'
                },
                {
                    id: 1,
                    title: 'hello',
                    sentence: 'hello world',
                    meaning: '你好'
                },
            ]
            $scope.words.forEach(function (word) {
                // word.
            })

            var freshWords = function () {
                if ($stateParams.words && $stateParams.words.length) {
                    $scope.words = $stateParams.words
                } else
                    dictService.getWordList($stateParams.dictId).then(function (response) {
                        $scope.words = response.data;
                    })
            };

            // freshWords();

            $scope.$on("$ionicSlides.sliderInitialized", function (event, data) {
                startTime = new Date();
            });

            $scope.$on("$ionicSlides.slideChangeStart", function (event, data) {
                if(data.slider.activeIndex < oldIndex) return;

                var TimeDelta = new Date() - startTime;


            });

            $scope.$on("$ionicSlides.slideChangeEnd", function (event, data) {
                startTime = new Date();
            });
        }])
 